/**
 * FileName: answer_1
 * Author:   why
 * Date:     2019/3/13 11:39
 * Description:
 */
package algorithm.leetcode.problem_94;

import java.util.ArrayList;
import java.util.List;

public class answer_1 {

    public class TreeNode {
       int val;
       TreeNode left;
       TreeNode right;
       TreeNode(int x) { val = x; }
   }
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> collect = new ArrayList<>();
        addTree(root, collect);
        return collect;
    }

    public void addTree(TreeNode root, List<Integer> collect) {
        if (root != null) {
            if (root.left != null) {
                addTree(root.left, collect);
                collect.add(root.val);
            } else {
                collect.add(root.val);
            }
            if (root.right != null) {
                addTree(root.right, collect);
            }

        } else {
            return;
        }

    }
}
